@@ -13,6 +13,15 @@ class @AgentEditPage |
||
| 13 | 13 |
e.preventDefault() |
| 14 | 14 |
alert 'Sorry, there appears to be an error in your JSON input. Please fix it before continuing.' |
| 15 | 15 |
|
| 16 |
+ if $(".link-region").length && $(".link-region").data("can-receive-events") == false
|
|
| 17 |
+ $(".link-region .select2-linked-tags option:selected").removeAttr('selected')
|
|
| 18 |
+ |
|
| 19 |
+ if $(".control-link-region").length && $(".control-link-region").data("can-control-other-agents") == false
|
|
| 20 |
+ $(".control-link-region .select2-linked-tags option:selected").removeAttr('selected')
|
|
| 21 |
+ |
|
| 22 |
+ if $(".event-related-region").length && $(".event-related-region").data("can-create-events") == false
|
|
| 23 |
+ $(".event-related-region .select2-linked-tags option:selected").removeAttr('selected')
|
|
| 24 |
+ |
|
| 16 | 25 |
$("#agent_name").each ->
|
| 17 | 26 |
# Select the number suffix if this is a cloned agent. |
| 18 | 27 |
if matches = this.value.match(/ \(\d+\)$/) |
@@ -103,26 +112,32 @@ class @AgentEditPage |
||
| 103 | 112 |
$(".link-region .select2-container").hide()
|
| 104 | 113 |
$(".link-region .propagate-immediately").hide()
|
| 105 | 114 |
$(".link-region .cannot-receive-events").show()
|
| 115 |
+ $(".link-region").data("can-receive-events", false)
|
|
| 106 | 116 |
|
| 107 | 117 |
showLinks: -> |
| 108 | 118 |
$(".link-region .select2-container").show()
|
| 109 | 119 |
$(".link-region .propagate-immediately").show()
|
| 110 | 120 |
$(".link-region .cannot-receive-events").hide()
|
| 121 |
+ $(".link-region").data("can-receive-events", true)
|
|
| 111 | 122 |
@showEventDescriptions() |
| 112 | 123 |
|
| 113 | 124 |
hideControlLinks: -> |
| 114 | 125 |
$(".control-link-region").hide()
|
| 126 |
+ $(".control-link-region").data("can-control-other-agents", false)
|
|
| 115 | 127 |
|
| 116 | 128 |
showControlLinks: -> |
| 117 | 129 |
$(".control-link-region").show()
|
| 130 |
+ $(".control-link-region").data("can-control-other-agents", true)
|
|
| 118 | 131 |
|
| 119 | 132 |
hideEventCreation: -> |
| 120 | 133 |
$(".event-related-region .select2-container").hide()
|
| 121 | 134 |
$(".event-related-region .cannot-create-events").show()
|
| 135 |
+ $(".event-related-region").data("can-create-events", false)
|
|
| 122 | 136 |
|
| 123 | 137 |
showEventCreation: -> |
| 124 | 138 |
$(".event-related-region .select2-container").show()
|
| 125 | 139 |
$(".event-related-region .cannot-create-events").hide()
|
| 140 |
+ $(".event-related-region").data("can-create-events", true)
|
|
| 126 | 141 |
|
| 127 | 142 |
showEventDescriptions: -> |
| 128 | 143 |
if $("#agent_source_ids").val()
|
@@ -56,4 +56,43 @@ describe "Creating a new agent", js: true do |
||
| 56 | 56 |
click_on "SF Weather" |
| 57 | 57 |
expect(page).to have_content "Editing your WeatherAgent" |
| 58 | 58 |
end |
| 59 |
+ |
|
| 60 |
+ context "clearing unsupported fields of agents" do |
|
| 61 |
+ before do |
|
| 62 |
+ visit new_agent_path |
|
| 63 |
+ end |
|
| 64 |
+ |
|
| 65 |
+ it "does not send previously configured sources when the current agent does not support them" do |
|
| 66 |
+ select2("Website Agent", from: "Type")
|
|
| 67 |
+ select2("SF Weather", from: 'Sources')
|
|
| 68 |
+ select2("Webhook Agent", from: "Type")
|
|
| 69 |
+ fill_in(:agent_name, with: "No sources") |
|
| 70 |
+ click_on "Save" |
|
| 71 |
+ expect(page).to have_content("No sources")
|
|
| 72 |
+ agent = Agent.find_by(name: "No sources") |
|
| 73 |
+ expect(agent.sources).to eq([]) |
|
| 74 |
+ end |
|
| 75 |
+ |
|
| 76 |
+ it "does not send previously configured control targets when the current agent does not support them" do |
|
| 77 |
+ select2("Commander Agent", from: "Type")
|
|
| 78 |
+ select2("SF Weather", from: 'Control targets')
|
|
| 79 |
+ select2("Webhook Agent", from: "Type")
|
|
| 80 |
+ fill_in(:agent_name, with: "No control targets") |
|
| 81 |
+ click_on "Save" |
|
| 82 |
+ expect(page).to have_content("No control targets")
|
|
| 83 |
+ agent = Agent.find_by(name: "No control targets") |
|
| 84 |
+ expect(agent.control_targets).to eq([]) |
|
| 85 |
+ end |
|
| 86 |
+ |
|
| 87 |
+ it "does not send previously configured receivers when the current agent does not support them" do |
|
| 88 |
+ select2("Website Agent", from: "Type")
|
|
| 89 |
+ select2("ZKCD", from: 'Receivers')
|
|
| 90 |
+ select2("Email Agent", from: "Type")
|
|
| 91 |
+ fill_in(:agent_name, with: "No receivers") |
|
| 92 |
+ click_on "Save" |
|
| 93 |
+ expect(page).to have_content("No receivers")
|
|
| 94 |
+ agent = Agent.find_by(name: "No receivers") |
|
| 95 |
+ expect(agent.receivers).to eq([]) |
|
| 96 |
+ end |
|
| 97 |
+ end |
|
| 59 | 98 |
end |
@@ -38,7 +38,7 @@ bob_disabled_website_agent: |
||
| 38 | 38 |
user: bob |
| 39 | 39 |
events_count: 1 |
| 40 | 40 |
schedule: "midnight" |
| 41 |
- name: "Disabled ZKCD" |
|
| 41 |
+ name: "Disabled Agent" |
|
| 42 | 42 |
guid: <%= SecureRandom.hex %> |
| 43 | 43 |
options: <%= {
|
| 44 | 44 |
:url => "http://xkcd.com", |